package com.uchengwang.ui.base_ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/7/16.
 */

public class FeedbakAdapter extends BaseAdapter{

    private Context context;
    private List<String> list = new ArrayList<>();

    public FeedbakAdapter(Context context){
        this.context = context;
    }

    public void setData(List<String> list){
        this.list = list;
        notifyDataSetChanged();
    }

    public List<String> getData(){
        return list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        FeedbackVH vh = null;
        if (view == null){
            vh = new FeedbackVH();
            view = LayoutInflater.from(context).inflate(R.layout.feedback_item, null, false);

            vh.item_image = (ImageView) view.findViewById(R.id.feedback_item_image);

            view.setTag(vh);
        }else {
            vh = (FeedbackVH) view.getTag();
        }

        String s = list.get(i);
        ImageManager.getInstance().loadImage(context, vh.item_image, s, ImageManager.ImageType.ROUND);

        return view;
    }

    private class FeedbackVH {
        private ImageView item_image;
    }
}
